package com.xiangban.controller;

import com.xiangban.aop.Permission;
import com.xiangban.model.Shop;
import com.xiangban.model.ShopLogin;
import com.xiangban.model.dto.ShopLoginDto;
import com.xiangban.model.res.ApiResult;
import com.xiangban.service.ShopService;
import com.xiangban.service.impl.ShopServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Mr. MaYaYun
 * @Data 2021/11/16 16:26
 */
@RestController
@RequestMapping("/shop")
@Api(tags = "商家管理")
public class ShopController {
    @Autowired
    private ShopService shopService;

    @PostMapping("/login")
    @ApiOperation("商家登录")
    public ApiResult<Object> login(@RequestBody ShopLogin shopLogin){
        return ApiResult.newSuccess(shopService.login(shopLogin));
    }

    @PostMapping("/getShopPermissionInformation")
    @ApiOperation("获取商家权限信息")
    @Permission(permission = "admin:shop:getShopPermissionInformation")
    public ApiResult<Object> getShopPermissionInformation(){
        ShopLoginDto shopLoginDto = shopService.getShopPermissionInformation();
        return ApiResult.newSuccess(shopLoginDto);
    }

    @PostMapping("/logout")
    @ApiOperation("商家登出")
    public ApiResult<Object> logout(){
        shopService.losePermissionMenu();
        shopService.loseToken();
        return ApiResult.newSuccess();
    }

    @PostMapping("/getShopInformation")
    @ApiOperation("获取商家信息")
    @Permission(permission = "admin:shop:getShopInformation")
    public ApiResult<Object> getShopInformation(){
        return ApiResult.newSuccess(shopService.getShopInformation());
    }

    @PostMapping("/updateShopInfo")
    @ApiOperation("修改商家信息")
    @Permission(permission = "admin:shop:updateShopInfo")
    public ApiResult<Object> updateShopInformation(@RequestBody Shop shop){
        shopService.updateShopInformation(shop);
        return ApiResult.newSuccess();
    }

    @PostMapping("/updateShopPassword")
    @ApiOperation("修改登录密码")
    @Permission(permission = "admin:shop:updateShopPassword")
    public ApiResult<Object> updateShopPassword(@RequestBody ShopLogin shopLogin){
        shopService.updateShopPassword(shopLogin);
        return ApiResult.newSuccess();
    }




}
